layui.config({
    base: $config.resUrl+'other/'//定义基目录
}).extend({
    ajaxExtention:'js/ajaxExtention',//加载自定义扩展，每个业务js都需要加载这个ajax扩展
    $tool:'js/tool',
    $api:'js/api'
}).use(['element','form','layer','laydate','ajaxExtention','$tool','$api'], function() {
	var $ = layui.jquery, 
	element = layui.element,
	laydate = layui.laydate,
	dtree = layui.dtree,
	form = layui.form,
	layer = layui.layer,
	$tool = layui.$tool,
    $api = layui.$api;
	
	//左边树形结构
var DTree_left = dtree.render({
		  elem: "#roleTree_left",
		  url: "/sys/role/tree.json",
		  request: {"id": $("#id").val()},//请求参数
		  initLevel: 2,
		  dot: false,//不显示一级图标小圆点
		  toolbar:true, // 开启工具栏
		  toolbarScroll:"#role_left_toolbarDiv", // 工具栏绑定div
		  toolbarShow:[], // 工具栏自带的按钮制空
		  menubar:true,
		  checkbar:true,
		  checkbarType: "no-all", // 半选
		  checkbarData: "choose",
		  menubarTips:{
			  toolbar: ["moveDown","moveUp","refresh","searchNode"], // 指定工具栏吸附的menubar按钮
			  group: ["moveDown", "moveUp", "refresh", "searchNode"] //按钮组
		  },
		  menubarFun: {
			  remove: function(checkbarNodes){ // 必须将该方法实现了，节点才会真正的从后台删除哦
				  alert(JSON.stringify(checkbarNodes));
				  return true;
			  }
		  }
		});
	dtree.on("node('roleTree_left')", function(data){
		layer.msg(JSON.stringify(data.param));
	});
	
	//获取左边树中选中节点
	$("#roleTree_left_btn").click(function(){
		var params = dtree.getCheckbarNodesParam("roleTree_left");
		layer.msg(JSON.stringify(params));
	});

	//调用左边树形删除节点
	$("#roleTree_btn").click(function(){
		//执行后会调用树中remove方法
		DTree_left.menubarMethod().remove();
	});
	
	//右边树
	dtree.render({
		  elem: "#roleTree_right",
		  url: "/sys/role/roleUserTree.json",
		  request: {"id": $("#id").val()},//请求参数
		  initLevel: 2,
		  dot: false,//不显示一级图标小圆点
		  toolbar:true, // 开启工具栏
		  toolbarScroll:"#role_right_toolbarDiv", // 工具栏绑定div
		  toolbarShow:[], // 工具栏自带的按钮制空
		  menubar:true,
		  checkbar: true,
		  checkbarType: "no-all", // 半选
		  menubarTips:{
		    toolbar:["moveDown","moveUp","refresh","searchNode"], // 指定工具栏吸附的menubar按钮
		    group:["moveDown", "moveUp", "refresh", "searchNode"] // 按钮组制空
		  }
	});
	
	dtree.on("node('roleTree_right')", function(data){
		layer.msg(JSON.stringify(data.param));
	});
	
	//获取右边树中选中节点
	$("#roleTree_right_btn").click(function(){
		var params = dtree.getCheckbarNodesParam("roleTree_right");
		layer.msg(JSON.stringify(params));
	});
});
